﻿using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using ZhuXingFamilys.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;

namespace ZhuXingFamilys.MainFamilyView
{
    [Transaction(TransactionMode.Manual)]
    public class MainFamilyVIewCommand : IExternalCommand
    {
       
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            if (commandData == null)
            {
                MessageBox.Show("Please open a document");
                return Result.Failed;
            };

            //objFrmAddStudent = new MainFamilyView("");


            MainFamilyView form = MainFamilyView.GetInstance();
            //将窗口绑定到主窗口之上
            System.Windows.Interop.WindowInteropHelper mainUI = new System.Windows.Interop.WindowInteropHelper(form);
            mainUI.Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;


            form.Show();
            form.Activate();


            if (form.WindowState == WindowState.Minimized)
            {
                form.WindowState = WindowState.Normal;
            }
            //if (form.WindowState == WindowState.Minimized || form.WindowState == WindowState.Normal)
            //{
            //}




            //MainFamilyView form = new MainFamilyView("");
            //if(Application.Current.Windows == null) {
            //    foreach (Window item in Application.Current.Windows)
            //    {
            //        MainFamilyView form = new MainFamilyView("");
            //        if (item != form)
            //        {
            //            form.Show();
            //            return Result.Succeeded;
            //        }

            //    }
            //}
            //UserLogin userLogin = new UserLogin();
            //if (userLogin.DialogResult==true)
            //{
            //MainFamilyView form = new MainFamilyView("");
            //form.Show();
            return Result.Succeeded;
            //}
           
            //return Result.Failed;

        }
       

    }
}
